package cn.edu.cdu.health.service.impl;

import cn.edu.cdu.health.entity.Diagnosis;
import cn.edu.cdu.health.entity.PageDto;
import cn.edu.cdu.health.entity.PageResult;
import cn.edu.cdu.health.mapper.DiagnosisMapper;
import cn.edu.cdu.health.service.DiagnosisService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class DiagnosisServiceImpl
        extends ServiceImpl<DiagnosisMapper, Diagnosis>
        implements DiagnosisService {

    @Override
    public PageResult<Diagnosis> getDiagnosisPage(PageDto pageDto) {
        Page<Diagnosis> page = new Page<>(pageDto.getPageNum(), pageDto.getPageSize());
        QueryWrapper<Diagnosis> wrapper = new QueryWrapper<>();
        // 添加搜索条件
        if (StringUtils.hasText(pageDto.getKeyword())) {
            wrapper.like("symptoms", pageDto.getKeyword())
                    .or()
                    .like("diagnosis_result", pageDto.getKeyword());
        }
        // 可在此添加查询条件
        Page<Diagnosis> result = baseMapper.selectPage(page, wrapper);
        return new PageResult<>(
                result.getRecords(),
                result.getTotal(),
                result.getSize(),
                result.getCurrent()
        );
    }
}